﻿
using System;
using System.IO;

using GECS.Core;

namespace GECS.MapEngine {

	/// <summary>
	/// This class is required to know all the information about the maps and to
	/// switch the maps more easily from the MapManager class.
	/// </summary>
    public class MapInfo {

		/// <summary>
		/// The data of the map. Use '\n' to indicate new rows.
		/// </summary>
        public string MapData = "";

        /// <summary>
        /// The default tile size.
        /// </summary>
        public int tileSize = 32;

        /// <summary>
        ///  The MapLoader used to load this map.
        /// </summary>
        public MapLoader loader = null;

        /// <summary>
        /// Loads MapInfo from an external file.
        /// </summary>
        /// <param name="fname">The name of the file.</param>
        /// <param name="loader">The MapLoader to be used.</param>
        /// <param name="tsize">The tile size.</param>
        /// <returns>The created MapInfo object.</returns>
        public static MapInfo LoadFromFile(string fname, MapLoader loader, int tsize) {
            MapInfo info = new MapInfo();
            string[] data = File.ReadAllLines(Game.GetFullFileName(fname));
            for (int i=0; i<data.Length; i++) {
                info.MapData += data[i] + "\n";
            }
            info.loader = loader;
            info.tileSize = tsize;
            return info;
        }
        
        /// <summary>
        /// Sets the MapLoader to be used.
        /// </summary>
        /// <param name="ldr">The MapLoader to be used.</param>
        public void SetMapLoader(MapLoader ldr){
        	loader = ldr;
        }
        
        /// <summary>
        /// Called when this MapInfo is used by the Map.
        /// </summary>
        public virtual void MapLoaded(){}

    }

}
